# Maintainer: Some One <some.one@some.email.com>

_realname=cunit
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
_distname="CUnit"
_distver="2.1-3"
pkgver=2.1.3
pkgrel=3
pkgdesc="Lightweight system for writing, administering, and running unit tests in C (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://cunit.sourceforge.io/'
license=('LGPL2.1')
source=("https://downloads.sourceforge.net/project/cunit/CUnit/2.1-3/CUnit-2.1-3.tar.bz2"
        "001-posix-layout.patch"
        "002-fix-shared.patch")
sha256sums=('f5b29137f845bb08b77ec60584fdb728b4e58f1023e6f249a464efa49a40f214'
            '520300bb55ad2a72981c87596dd13f5d2bd095ef2259c74ef53d136ae218ebea'
            'be56af8ed53dbbdf8c22801dfa4c21d26297901d9731a931f3dd8db524de086d')

prepare() {
  cd "$srcdir/"${_distname}-${_distver}
  patch -p1 -i ${srcdir}/001-posix-layout.patch
  patch -p1 -i ${srcdir}/002-fix-shared.patch
  
  libtoolize --force --copy
  aclocal
  autoheader
  automake --add-missing --include-deps --copy
  autoconf
}

build() {
  cd "${srcdir}"/${_distname}-${_distver}
  rm -rf "${srcdir}"/build-${CARCH} | true
  mkdir -p "${srcdir}"/build-${CARCH} 
  cp -Rf ${srcdir}/${_distname}-${_distver}/* "${srcdir}"/build-${CARCH} 
  cd "${srcdir}"/build-${CARCH}

  # These checks fail with ucrt: https://github.com/msys2/CLANG-packages/issues/21
  export ac_cv_func_time=yes
  export ac_cv_func_ctime=yes

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-debug \
    --enable-static \
    --enable-shared
  sed "s|\/Users\/aks\/CUnitHome|${MINGW_PREFIX}|" -i cunit.pc
  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
}
